<template>
  <!-- 上传厂家证照的表格modal -->
  <div>
    <basic-modal 
        :modalOpt="modal" 
        :buttonText="['','关闭']"
        @onMakeSure="onPush"
        @closeModal="closeModal"
        :footer="footer" 
    >
      <template #cusBtn>
        <a-button type="primary" v-print="printObj"  > 打印 </a-button>
      </template>
      <template>
        <batch-operat-btn v-if="editable" :isView="false" :addData="true" @onAddData="onAddData">
          <template #cusBtn> </template>
        </batch-operat-btn>
        <div style="display:none">
          <print-html 
            ref="print" id="print"
            :saleOrderPid="pid"
            :infoDatas="infoDatas"
            :BarCode="BarCode"
            :columns="columns"
            ></print-html>
        </div>
        <a-list-info :infoDatas="infoDatas" :haveBarCode="true" :BarCode="BarCode"  />
        <div class="recordBox">
          <a-list-table
            :columns="columns"
            :tableData="listdata"
            :isSelecttion="false"
            :loading="loading"
            :scroll="{ y: null }"
            :pagination="pagination"
            :renderStateByField="['saleOrderState']"
            @onTableChange="handleTableChange"
          >
          </a-list-table>
        </div>
      </template>
    </basic-modal>
  </div>
</template>

<script>
import basicModal from '@/views/app/biz/common/basicModal'
import aListTable from '@/views/app/biz/common/aListTable'
import aListInfo from '@/views/app/biz/common/aListInfo'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import printHtml from './printHtml.vue'
import {totalPrice} from '@/views/app/biz/common/js/computed'
import {columnsDetail,infoDatas} from './dataConfig'
import storage from 'store'
import {
  getInfoByPid,
  getDetailByConditions,
  getDetailByConditionsCount
} from './saleOrder'

export default {
  components: {
    basicModal,
    aListTable,
    batchOperatBtn,
    aListInfo,
    printHtml
  },
  data() {
    return {
      printObj: {
        id: "print",
        preview: false,//是否开启打印预览
        previewTitle: '打印预览', // The title of the preview window. The default is 打印预览
        popTitle: '销售单',
        extraCss: "https://cdn.bootcdn.net/ajax/libs/animate.css/4.1.1/animate.compat.css, https://cdn.bootcdn.net/ajax/libs/hover.css/2.3.1/css/hover-min.css",
        extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
        previewBeforeOpenCallback (vue) {
          console.log('正在加载预览窗口')
        },
        previewOpenCallback (vue) {
          console.log('已经加载完预览窗口')
        },
        beforeOpenCallback (vue) {
          vue.printLoading = true
          console.log('打开之前')
        },
        openCallback (vue) {
          vue.printLoading = false
          console.log('执行了打印')
        },
        closeCallback (vue) {
          console.log('关闭了打印工具')
        }
      },
      footer:undefined,
      editable:false,
      loading: false,
      modal: {
        modalVisible: false,
        modalTitle: '审核证照',
        modalWidth: '95vw',
        maxHeight:'70vh'
      },
      BarCode:null,
      infoDatas:infoDatas,
      columns:columnsDetail,
      sData: {
        saleOrderPid: null,
      },
      listdata: [],
      pagination: {
        //分页配置
        current: 1, //当前页码 current
        pageSize: 10, //每页显示条数 pageSize
        total: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ['1', '5', '10', '100'],
      },
      listKey: 0,
      pid: '',
      zzPid:'',
      sysSeq: 0,
      loadings: false,
    }
  },
  computed: {},
  mounted() {},
  methods: {
    // // 弹出模态框
    showModal(val,record) {
      this.pid = val
      this.record=record
      this.modal.modalVisible = true
      this.modal.modalTitle = '查看详情'
      this.sData.saleOrderPid= val
      this.getSBypid(val)
      this.getTotal()
      this.getDetailBypid(this.sData)
      
    },
    // 关闭模态详细框
    closeModal() {
      this.modal.modalVisible = false
      this.$emit('close')
      Object.assign(this.$data,this.$options.data())
    },
    closeModal2() {
      this.modal.modalVisible = false
      this.$emit('ok')
      Object.assign(this.$data,this.$options.data()) 
    },
    //
    onAddData() {
      this.$refs.addSellerLicChildModal.addModal(this.pid)
    },

    // 审核
    onPush() {
    },

    // 得到销售订单消息
    async getSBypid(val) {
      let res = await getInfoByPid(val)
      if (res && res.code && res.code === 'C1') {
        this.sysSeq = res.data.sysSeq
        this.BarCode=res.data.saleOrderNo
        this.printObj.popTitle='销售单号：'+res.data.saleOrderNo+' , 采购单位：'+res.data.customerName
        for (const key in res.data) {
            for (const item of this.infoDatas) {
                if(key==item.id){
                    item.value=res.data[key]
                }
            }
        }
      }
    },
    // 触发改变页码,筛选,排序时的回调
    handleTableChange(pagination, filters, sorter) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.getDetailBypid(this.sData)
    },
    // 初始化页面时得到总数
    async getTotal() {
      let pages = ''
      pages = await getDetailByConditionsCount(this.sData)
      console.log(pages)
      if (pages && pages.code && pages.code === 'C1') {
        const pagination = { ...this.pagination }
        pagination.total = pages.data
        this.pagination = pagination
        this.pagination.showTotal =  (showTotal) => {return `共 ${showTotal} 条`}
      }
    },
    //得到初始化订单商品list
    async getDetailBypid(params) {
      console.log('请求列表时传入的数据', params)
      this.loading = true
      let listdata = []
      let res = ''
      res = await getDetailByConditions(params, this.pagination)
      this.loading = false
      console.log(res)
      if (res && res.code && res.code === 'C1' && res.data) {
        const resdata = res.data
        this.orgList=res.data
         for (let item of resdata) {
            listdata.push({
               key: item.pid,
               ...item,
               totalPriceV:totalPrice(item.iunitprice,item.num)
               }
            )
         }
         this.listdata =listdata
      } else {
        this.listdata = []
      }
    },
  },
}
</script>

<style>
.recordBox {
  width: 100%;
  min-height: 80px;
}
</style>